D:\git\skunkworks\herald-for-cpp\herald-tests\crossplatform-tests.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2021 Herald Project Contributors |
2 | | // SPDX-License-Identifier: Apache-2.0 |
3 | | // |
4 | | |
5 | | #include <iostream> |
6 | | #include <fstream> |
7 | | #include <string> |
8 | | |
9 | | #include "catch.hpp" |
10 | | |
11 | | #include "herald/herald.h" |
12 | | |
13 | | #include "test-util.h" |
14 | | |
15 | 0 | TEST_CASE("crossplatform-contact-identifier", "[.][payload][crossplatform][basic]") { |
16 | 0 | SECTION("crossplatform-contact-identifier") { |
17 | 0 | // Check output file can be created |
18 | 0 | auto fn = testutil::fullFilename("contactIdentifier.csv"); |
19 | 0 | INFO("Output filename: " << fn); |
20 | 0 | std::ofstream cppOut(fn); |
21 | 0 | cppOut << "day,period,matchingKey,contactKey,contactIdentifier" << std::endl; |
22 | 0 |
|
23 | 0 | herald::payload::simple::SecretKey ks1((std::byte)0, 2048); |
24 | 0 | herald::payload::simple::K myK(2048, 2000, 240); // have to generate 2000 to get the right end key value |
25 | 0 | for (int day = 0; day <= 10; ++day) { |
26 | 0 | auto mk = herald::datatype::Base64String::encode(myK.matchingKey(ks1, day)).encoded(); |
27 | 0 | for (int period = 0; period <= 240; ++period) { |
28 | 0 | cppOut << day << "," << period << "," |
29 | 0 | << mk << "," |
30 | 0 | << herald::datatype::Base64String::encode(myK.contactKey(ks1, day, period)).encoded() << "," |
31 | 0 | << herald::datatype::Base64String::encode(myK.contactIdentifier(ks1, day, period)).encoded() << std::endl; // TODO verify EOL character is consistent |
32 | 0 | } |
33 | 0 | } |
34 | 0 | cppOut.close(); // flushes and closes |
35 | 0 |
|
36 | 0 | // Now ensure our output matches the other platforms' |
37 | 0 | testutil::validateEqual("contactIdentifier.csv"); |
38 | 0 | } |
39 | 0 | } |
40 | | |
41 | | |
42 | 0 | TEST_CASE("crossplatform-k-matchingkeyseed", "[.][payload][k-matchingkeyseed][basic]") { |
43 | 0 | SECTION("crossplatform-k-matchingkeyseed") { |
44 | 0 | // Check output file can be created |
45 | 0 | auto fn = testutil::fullFilename("kMatchingSeed2000.csv"); |
46 | 0 | INFO("Output filename: " << fn); |
47 | 0 | std::ofstream cppOut(fn); |
48 | 0 | cppOut << "day,matchingSeed" << std::endl; |
49 | 0 |
|
50 | 0 | herald::payload::simple::SecretKey ks1((std::byte)0, 2048); |
51 | 0 | herald::payload::simple::K myK(2048, 2000, 240); // have to generate 2000 to get the right end key value |
52 | 0 | auto last(herald::payload::simple::F::h(ks1)); |
53 | 0 | herald::payload::simple::MatchingKey nks; |
54 | 0 | // Note the indexes below are the value of i. I.e. today is day 0, tomorrow is day 1, etc. |
55 | 0 | // So we start with day 2001 (at index 2000) |
56 | 0 | cppOut << 2000 << "," << herald::datatype::Base64String::encode(last).encoded() << std::endl; |
57 | 0 | std::string firstTenDays[10]; |
58 | 0 | for (int day = 1999; day >= 0; --day) { |
59 | 0 | nks = herald::payload::simple::F::h(herald::payload::simple::F::t(last)); |
60 | 0 | auto mks = herald::datatype::Base64String::encode(nks).encoded(); |
61 | 0 | cppOut << day << "," |
62 | 0 | << mks << std::endl; |
63 | 0 | last = nks; |
64 | 0 | if (day < 10) { |
65 | 0 | firstTenDays[day] = mks; |
66 | 0 | } |
67 | 0 | } |
68 | 0 | cppOut.close(); // flushes and closes |
69 | 0 |
|
70 | 0 | auto tenDaysFn = testutil::fullFilename("kMatchingSeed.csv"); |
71 | 0 | INFO("Output filename: " << tenDaysFn); |
72 | 0 | std::ofstream cppOut2(tenDaysFn); |
73 | 0 | cppOut2 << "day,matchingSeed" << std::endl; |
74 | 0 | for (int i = 0;i < 10;++i) { |
75 | 0 | cppOut2 << i << "," << firstTenDays[i] << std::endl; |
76 | 0 | } |
77 | 0 | cppOut2.close(); // flushes and closes |
78 | 0 |
|
79 | 0 | // Now ensure our output matches the other platforms' |
80 | 0 | testutil::validateEqual("kMatchingSeed.csv"); |
81 | 0 | } |
82 | 0 | } |